#ifndef PLOTTER_H
#define PLOTTER_H

#include <QtGui>
#include <QFrame>
#include <QImage>
#define VERT_DIVS 7	//specify grid screen divisions
#define HORZ_DIVS 20

extern "C" {
extern struct {
  qint32 qsoFreq;
} gcom0_;
}

class CPlotter : public QFrame
{
  Q_OBJECT
public:
  explicit CPlotter(QWidget *parent = 0);
  ~CPlotter();

  QSize minimumSizeHint() const;
  QSize sizeHint() const;
  QColor m_ColorTbl[256];
  int m_plotZero;
  int m_plotGain;
  float   m_Span;

  void draw(float savg[]);		//draw new spectrum
  void SetRunningState(bool running);
  void setPlotZero(int plotZero);
  int getPlotZero();
  void setPlotGain(int plotGain);
  int getPlotGain();
  void SetPercent2DScreen(int percent);
  void SetCenterFreq(quint64 f);
  qint64 centerFreq();
  void SetStartFreq(quint64 f);
  qint64 startFreq();
  void SetFreqOffset(quint64 f);
  qint64 freqOffset();
  int plotWidth();
  void SetSpanFreq(quint32 s);
  void SetMaxdB(int max);
  void SetdBStepSize(int stepsz);
  void UpdateOverlay();
  void setWide(bool b);
  void setBinsPerPixel(int n);
  int binsPerPixel();
  void setFQSO(int n, bool bf);
  int fQSO();

signals:
  void NewCenterFreq(qint64 f);

public slots:

protected:
  //re-implemented widget event handlers
  void paintEvent(QPaintEvent *event);
  void resizeEvent(QResizeEvent* event);

private:

  // Private functions
  void DrawOverlay();
  void MakeFrequencyStrs();
  int XfromFreq(float f);
  float FreqfromX(int x);
  qint64 RoundFreq(qint64 freq, int resolution);

  bool IsPointCloseTo(int x, int xr, int delta)
  {
    return ((x > (xr-delta) ) && ( x<(xr+delta)) );
  }

  // Private members
  QPixmap m_2DPixmap;
  QPixmap m_OverlayPixmap;
  QPixmap m_WaterfallPixmap;
  QPixmap m_ScalePixmap;
  QSize   m_Size;
  QString m_Str;
  QString m_HDivText[HORZ_DIVS+1];
  bool    m_Running;
  double  m_CenterFreq;
  qint64  m_StartFreq;
  qint64  m_FreqOffset;
  int     m_Percent2DScreen;
  qint32  m_MaxdB;
  qint32  m_MindB;
  qint32  m_dBStepSize;
  qint32  m_FreqUnits;
  qint32  m_hdivs;
  qint32  m_fQSO;
  bool    m_wide;
  qint32  m_binsPerPixel;
  qint32  m_n60z;
};

#endif // PLOTTER_H
